package com.example.steveaoblogdemo.controller;

import com.example.steveaoblogdemo.service.impl.TagServiceImpl;
import com.example.steveaoblogdemo.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class TagController {
    @Resource
    TagServiceImpl tagService;

    @GetMapping("/tag/queryTag")
    public Result<?> queryTag(){
        return tagService.queryTag();
    }

    @PostMapping("/tag/addTag")
    public int addTag(@RequestParam(required = false) Integer id,@RequestParam(defaultValue = "") String tName){
        return tagService.addTag(id,tName);
    }

    @GetMapping("/tag/query")
    public Result<?> query(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "10")Integer pageSize,@RequestParam(defaultValue = "")String search){
        return tagService.query(pageNum,pageSize,search);
    }

    @GetMapping("/tag/queryTagById")
    public Result<?> queryById(@RequestParam(required = false) Integer id){
        return tagService.queryById(id);
    }

    @PutMapping("/tag/updateTag")
    public int update(@RequestParam(defaultValue = "")String tName,@RequestParam(required = false)Integer id){
        return tagService.updateTag(tName,id);
    }

    @PutMapping("/tag/deleteById")
    public Result<?> delete(@RequestParam(required = false) Integer id){
        return tagService.deleteTag(id);
    }

    @GetMapping("/tag/queryByTag")
    public Result<?> queryByTag(@RequestParam(required = false)Integer id){
        return tagService.queryByTag(id);
    }
}
